﻿<!--#include file="include/config.asp"-->
<!--#include file="include/conn_f.asp"-->
<!--#include file="include/md5.asp"-->
<!--#include file="ipcountry/ipcountry.asp" -->
<!--#include file="top.asp"-->
<!--#include file="left.asp"-->
<%
If Session("cust_id")="" Then
	Response.Write  "请先登录"
	Response.End
End If
card_id=saferequest("card_id",1)
cust_id=Session("cust_id")
amount=cint(request("amount"))
gameid=request("gameid")
gamename=request("gamename")
gamename_selected=request("gamename_selected") 
server_area=request("server_area")
servername=request("servername")

memo_cust=request("memo_cust")
'IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
'If IP="" Then
	IP=Request.ServerVariables("remote_addr")
'End If

ip_address=split(IP,",",-1,1)
If UBound(ip_address)>-1 and len(ip_address(0))>7 Then
	ipcountry=IP2Country(ip_address(0))
Else
	ipcountry="CN"
End If
'----------------------------------------
sql="select balance,buytimes,VIP,isactive from customer where cust_id="&cust_id
Set rs=conn.execute(sql)
Dim balance
balance=0
custom=0
If Not rs.eof Then
	balance=ccur(rs("balance"))
	ISVIP=cint(rs("VIP"))
	isactive=cint(rs("isactive"))
End If

sql="select * from card where card_id="&card_id
Set rs=conn.execute(sql)
If Not rs.eof Then
	If ISVIP=1 Then
		price=ccur(rs("VIP_price"))
	Else
		price=ccur(rs("price"))
	End If
	goods_type=rs("goods_type")
End If
rs.close
total_amount=price*amount

sql="insert into orders(cust_id,goods_type,card_1,card_1_amount,total_amount,memo_cust,order_time,IP,IPCOUNTRY)"
sql=sql&" values("&cust_id&","&goods_type&","&card_id&","&amount&","&total_amount&",'"&memo_cust&"',now(),'"&IP&"','"&ipcountry&"')"

conn.execute sql
sql="select LAST_INSERT_ID() from orders"
rs.open sql,conn
orders_id=rs(0)
rs.close

sql="insert into orders_detail(orders_id,goods_type,card_id,amount) values("&orders_id&","&goods_type&","&card_id&","&amount&")"
conn.execute sql
sql="select LAST_INSERT_ID() from orders_detail"
rs.open sql,conn
order_detail_id=rs(0)
rs.close

If goods_type=1 Then	
	If gamename_selected ="1" Then
		sql="select * from charge_option  where charge_option_id="&gamename
		Set rs=conn.execute(sql)
		If Not rs.eof Then
			charge_method=rs("option_name")
			server_ID=rs("option_value")
		End If
	Else
		charge_method=gamename
	End If
	sql="insert into charge_detail(orders_id,order_detail_id,game_account,charge_method,server_ID,server_area,servername) "
	sql=sql&"values("&orders_id&","&order_detail_id&",'"&gameid&"','"&charge_method&"','"&server_ID&"','"&server_area&"','"&servername&"')"
	conn.execute sql
	If trim(gameid)="" Then
		Response.Write "<br /><font color='red'>您的帐号没有填写!充值类的商品必须提供相关帐号,例如游戏帐号或者QQ号码.</font>"
		Response.End
	End If
End If

Response.Redirect "ckout.asp?orders_id="&orders_id


%>
</table>
<!--#include file="bottom.asp"-->
